<template>
  <el-dialog title="日志详情"  :close-on-click-modal="false" :visible.sync="show" class="dialog_index  dialog__log"
   :before-close="cancle">
    <el-table :data="tableData" v-loading="loading" height="100%"> 
      <el-table-column  label="操作"  width="120" prop="action"></el-table-column>
      <el-table-column  label="操作人" width="120" prop="create_name"></el-table-column>
      <el-table-column  label="操作时间"  width="180" prop="create_time"></el-table-column>
      <el-table-column  label="操作前内容"  width=""  prop="content_before" align="left">
        <template  slot-scope="scope">
          <div v-html="transform(scope.row.content_before)"></div>
        </template>
      </el-table-column>
      <el-table-column  label="操作后内容" width=""   prop="content_after" align="left">
         <template  slot-scope="scope">
            <div v-html="transform(scope.row.content_after)"></div>
         </template>
      </el-table-column>
   
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { log } from '@/api/support/fileType.js'
export default {
  data () {
    return {
      tableData:[]
    }
  },
  watch: {
    show:function(){
      if(this.show){
        this.loading = true
        this.getData()
      }
    }
  },
  props: {
    show: Boolean,
    closeDialog:Function,
    id:Number
  },
  methods: {
    getData() {
       let params = {
        log_id: this.id
      }
      log(params).then((res) =>{
        let data = res.data
        this.tableData= data
        this.loading = false
      })
    },
    transform(target){
      let str = ""
      target = JSON.parse(target)
      let isArray = target instanceof Array;
      if(isArray){
        for (let item in target){
          for(let i in target[item]){
            str+= i + ':' +target[item][i] +','
          }
          str+= '</br>'
        }
      }else{
        for(let i in target){
          str+= i + ':' +target[i] +','
        }
      }
      return str
    },
    cancle(){
      this.$emit('closeDialog')

    },
  }

}
</script>

<style>
</style>